package com.tanhua.server.controller;

import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 查询用户信息
     * @param userID
     * @return
     */
    @GetMapping
    public ResponseEntity getUserInfo(Long userID){
        UserInfoVo userInfoVo = userInfoService.getUserInfo(userID);

        return ResponseEntity.ok(userInfoVo);
    }

    /**
     * 用户资料 - 保存
     * @param userInfoVo
     * @return
     */
    @PutMapping
    public ResponseEntity updateUserInfo(@RequestBody UserInfoVo userInfoVo){
        userInfoService.updateUserInfo(userInfoVo);
        return ResponseEntity.ok(null);
    }

    /**
     * 用户资料 - 更新头像
     * @param headPhoto
     * @return
     */
    @RequestMapping(value = "/header",method = RequestMethod.POST)
    public ResponseEntity updatePhoto(MultipartFile headPhoto){
        userInfoService.updatePhoto(headPhoto);
        return ResponseEntity.ok(null);
    }
}
